from enum import Enum


class AdvanceApprovalEnum(Enum):
    UNPROCESSED = (0, "\u672a\u5904\u7406")  # 未处理
    APPROVED = (1, "\u6279\u51c6")  # 批准
    REJECTED = (2, "\u62d2\u7edd")  # 拒绝
    HANDLED = (3, "\u5df2\u5904\u7406")  # 已处理

    def __init__(self, code, msg):
        self._code = code
        self._msg = msg

    @property
    def code(self):
        return self._code

    @property
    def msg(self):
        return self._msg

    @staticmethod
    def get_by_name(name):
        try:
            # 将名称转换为大写，并查找匹配的枚举成员
            return AdvanceApprovalEnum[name.upper()]
        except KeyError:
            return None

    @staticmethod
    def get_by_type(code):
        # 遍历枚举成员，返回与code匹配的枚举成员
        for approval in AdvanceApprovalEnum:
            if approval.code == code:
                return approval
        return None
